import { stringToDate } from "@/generic/Utils";
import { Icon, Tag, Input, Checkbox, Button, Select } from 'antd';
import { FILE_OBJECT, PATH_SEPARATOR } from "@/generic/ConfigParams";
import styles from "../../BaseComponents/style.less";
import moment from 'moment';

const TRANS_TYPE = {
    ORG: { text: '原始', color: '' },
    PDF: { text: 'PDF', color: 'volcano' },
    READ: { text: '只读', color: 'gold' },
    MARK: { text: '水印', color: 'blue' },
    PWD: { text: '加密', color: 'green' },
}

// #### NEW_FIELDS ####  | 自定义的字段 or 修改原先的字段
// 规定自己添加的字段：首字母大写！ => 防止与原有字段冲突。
export const NEW_FIELDS = [
    { name: 'Name', handle: (source) => {
        if (source.path)
        return source.path.split(PATH_SEPARATOR).pop();
    } },
    {
        name: 'ShareType', handle: (source) => {
            if (source.convertTo)
            return TRANS_TYPE[source.convertTo].text + '文件';
        }
    },
    {
        name: 'ExpireDate', handle: (source) => {
            if (source.expire)
                // return moment(source.expire).fromNow();
                return moment(source.expire).format('MMMM Do YYYY, h:mm:ss a')
        }
    },
]

export const SHARE_NEWS = {
    fromUserID: { newKey: 'fromUser', resKey: 'nickName' },
    userID: { newKey: 'toUser', resKey: 'nickName' },
}

// #### TABLE_COLS ####
export const TABLE_COLS = [
    {
        dataIndex: 'Name', text: "名称", width: '30%',
        render: (name) => (
            <span style={{ cursor: "pointer", display: "contents" }}>
                <Icon theme={FILE_OBJECT.theme}
                    style={{ color: FILE_OBJECT.color }}
                    type={FILE_OBJECT.icon} />
                <span style={{ marginLeft: "3px" }}>{name}</span>
            </span>
        ),
        toDetail: { type: 'fileManage/updateCurrentPage', payload: { mark: 'detail' } },
    },
    {
        dataIndex: 'createdAt', text: "分享时间", width: '', isHidden: true,
        render: (date, _) => <span>{stringToDate(date)}</span>,
    },
    {
        dataIndex: SHARE_NEWS.fromUserID.newKey, text: "分享人", width: '', isHidden: true,
    },
    {
        dataIndex: SHARE_NEWS.userID.newKey, text: "接收人", width: '',
    },
    {
        dataIndex: 'convertTo', text: "类型", width: '', isHidden: true,
        render: (type) => <Tag color={TRANS_TYPE[type].color}>{TRANS_TYPE[type].text}</Tag>,
    },
]

// #### HEADER_OPTS ####
export const HEADER_OPTS = {
    left: [
        {
            isGroup: true, className: 'headerBtns',
            groups: [
                {
                    text: '全部',
                    args: { icon: 'share-alt', className: styles.btnUsed},
                    msgTip: '删除',
                },
                {
                    text: '收到',
                    args: { icon: 'login', },
                },
                {
                    text: '分享',
                    args: { icon: 'logout', },
                    // action: { type: 'fileManage/methodAdapter', method: '', payload: {} },
                },
            ]
        },
        {
            text: '删除', isHidden: true,
            args: { icon: 'delete', type: 'danger'},
            confirm: {
                name: '文件',
                action: { type: 'fileManage/methodAdapter', method: 'delete', payload: {} },
            },
            msgTip: '删除',
        },
    ],
    right: {
        onSearch: () => { },
    },
}

//  #### DETAIL_ARGS ####
const leave = { type: 'fileManage/updateCurrentPage', payload: null }
export const DETAIL_ARGS = {
    detailTitle: '分享详情',
    updateTitle: '用户修改',
    leave: leave,
    defaultLabelCol: { span: 5 },
    defaultWrapperCol: { span: 15 },
    defaultColSpan: { xs: 24, md: 12, lg: 12 },
    content: {
        account: [
            { label: '文件名', index: 'name' },  // TJ
            { label: '分享人', index: SHARE_NEWS.fromUserID.newKey },
            { label: '接收人', index: SHARE_NEWS.userID.newKey },
            { label: '分享类型', index: 'ShareType' },
            { label: '分享时间', index: 'createdAt', isDate: true },
            { label: '失效时间', index: 'expire' },  // TJ
            
        ],
        fileInfo: [
            { label: '更多文件详情', index: 'hash' },
        ],
    },
    footer: [
        {
            elem: Icon,
            style: { float: 'left', height: '32px', lineHeight: '32px' },
            args: {
                type: 'arrow-left',
            },
            onClick: (dispatch) => { dispatch(leave) },
            // html: <xxx />  // 复杂的直接返回组件
        },
        {
            mark: 'detail',
            elem: Button,
            style: { float: 'right', marginRight: '8px' },
            args: {
                // icon: 'edit',
                type: 'danger',
            },
            text: '删除',
            onClick: (dispatch) => { }
        },
    ],
}